package com.weixing.mall.provider.controller.admin;


import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.dto.CategorySpecDto;
import com.weixing.mall.provider.model.query.CategorySpecQuery;
import com.weixing.mall.provider.service.ICategorySpecService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName CategorySpecController
 * @Description TODO <br/>
 * @Author gjq
 * @Modified By:
 * @Date 2019/8/12
 * @Version 1.0
 **/
@RestController
@RequestMapping("categorySpec")
@Api(value = "商品类目规格APi", tags = "商品类目规格")
public class CategorySpecController extends BaseController {
    @Autowired
    private ICategorySpecService categorySpecService;

    @ApiOperation(value = "根据条件加载商品类目规格")
    @GetMapping("getList")
    public Result list(CategorySpecQuery categorySpecQuery) {
        return ResultUtil.success(categorySpecService.selectList(categorySpecQuery));
    }

    @ApiOperation(value = "保存商品类目规格")
    @PostMapping("save")
    @NoRepeatSubmit
    public Result save(@Validated CategorySpecDto categorySpecDto) {
        categorySpecService.save(categorySpecDto);
        return ResultUtil.success();
    }

    @ApiOperation(value = "删除类目规格")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "规格id", paramType = "path", dataType = "long")
    })
    @PostMapping(value = "del/{id}")
    public Result del(@PathVariable long id) {
        return categorySpecService.removeById(id)? ResultUtil.success() : ResultUtil.error();
    }
}
